package com.ws.wuse.http;

import com.ws.base.rxvolley.RxVolley;
import com.ws.base.rxvolley.client.HttpCallback;
import com.ws.base.rxvolley.client.HttpParams;
import com.ws.base.rxvolley.client.ProgressListener;
import com.ws.base.util.BaseUtil;
import com.ws.wuse.app.Constant;

/**
 * User: zhanghang
 * Date: 2016-03-24
 * Time: 09:58
 * FIXME
 */
public class HttpApi {

    // 请求头公共参数
    private HttpParams getParams() {
        HttpParams params = new HttpParams();
        params.put("imei", "12345");
        /*if (UserInfoCache.getInstance().isLogin()) {
            params.put("userId", UserInfoCache.getInstance().getUserId() + "");
            params.put("userToken", UserInfoCache.getInstance().getUserToken());
        }*/
        return params;
    }

    private void post(String url, HttpParams params, HttpCallback callback) {
        RxVolley.getInstance().post(Constant.HTTP_URL + url, params, callback);
    }

    private void post(String url, HttpParams params, ProgressListener listener, HttpCallback callback) {
        RxVolley.getInstance().post(Constant.HTTP_URL + url, params, listener, callback);
    }

    // 用户登录
    public void login(String mobile, String password, HttpCallback callback) {
        HttpParams params = getParams();
        params.put("mobile", mobile);
        params.put("password", BaseUtil.md5(password));
        post("login/v2.0/mobileLoginYx", params, callback);
    }

    /**
     * ************************************ 单例 **********************************************
     */
    private volatile static HttpApi mInstance;

    private HttpApi() {
    }

    public static HttpApi HttpApi() {
        if (mInstance == null) {
            synchronized (HttpApi.class) {
                if (mInstance == null) {
                    mInstance = new HttpApi();
                }
            }
        }
        return mInstance;
    }
}